/*
@Time : 2021/8/2 下午6:04
@Author : Mrxuexi
@File : mysql
@Software: GoLand
*/
package dao

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
)

var (
	DB *gorm.DB
)


func Dbinit()(err error){
	//连接数据库
	DB,err = gorm.Open(mysql.New(mysql.Config{
		DSN:"root:root@tcp(127.0.0.1:3306)/practice?charset=utf8&parseTime=True&loc=Local",
		DefaultStringSize: 256,
	}),&gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			TablePrefix: "todo_",   // 表名前缀，`User`表为`t_users`
		},
		DisableForeignKeyConstraintWhenMigrating: true,
	})

	if err != nil {
		return
	}
	return
}
